package cn.weakup.thread.state;

import java.util.concurrent.TimeUnit;

/**
 * @author Dawn
 * @version 1.0.0
 * @desc
 * @date 2022/5/4
 */
public class ThreadState {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread();
        thread.start();

        Thread waitTimeThread = new Thread(new WaitTime(), "WaitTimeThread");
        // 初始化，未调用start时：NEW
        System.out.println("waitTimeThread：" + waitTimeThread.getState());
        waitTimeThread.start();
        System.out.println("waitTimeThread：" + waitTimeThread.getState());

        Thread waitStateThread = new Thread(new WaitState(), "WaitStateThread");
        waitStateThread.start();

        // BlockedThread--01会抢占锁，BlockedThread--02会阻塞
        Thread block01 = new Thread(new BlockedThread(), "BlockedThread--01");
        block01.start();
        // 确保block01先执行
        TimeUnit.SECONDS.sleep(1);
        Thread block02 = new Thread(new BlockedThread(), "BlockedThread--02");
        block02.start();

        System.out.println("\n====================\n");
        TimeUnit.SECONDS.sleep(2);
        System.out.println("waitTimeThread：" + waitTimeThread.getState());
        System.out.println("waitStateThread：" + waitStateThread.getState());
        System.out.println("block01：" + block01.getState());
        System.out.println("block02：" + block02.getState());

        System.out.println("thread：" + thread.getState());

    }
}
